package com.example.controller;

import com.example.common.annotation.OperLog;
import com.example.common.enums.LogType;
import com.example.common.utils.R;
import com.example.system.entity.OperationLog;
import com.example.system.service.IOperationLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 王鹤蒲
 * @since 2023-10-07
 */
@RestController
@Api(value = "", tags = {""})
@RequestMapping("/operation-log")
public class OperationLogController {

    @Autowired
    private IOperationLogService iOperationLogService;

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public R saveOperationLog(@RequestBody OperationLog operationLog) {
        return iOperationLogService.saveOperationLog(operationLog);
    }

    @ApiOperation(value = "", notes = "")
    @OperLog(operation = "日志管理",type = LogType.DELETE)
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public R deleteById(@PathVariable("id") Integer id) {
        return iOperationLogService.deleteById(id);
    }

    @ApiOperation(value = "", notes = "")
    @OperLog(operation = "日志管理",type = LogType.DELETE)
    @RequestMapping(value = "/deleteBatch", method = RequestMethod.POST)
    @ResponseBody
    public R deleteByIds(@RequestBody Integer[] ids) {
        return iOperationLogService.deleteByIds(ids);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    @ResponseBody
    public R findPage(int currentPage, int pageSize, OperationLog operationLog) {
        return iOperationLogService.findPage(currentPage, pageSize, operationLog);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public R findOne(@PathVariable("id") Integer id) {
        return iOperationLogService.findOne(id);
    }

    @ApiOperation(value = "", notes = "")
    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    @ResponseBody
    public R findAll() {
        return iOperationLogService.findAll();
    }


    @ApiOperation(value = "", notes = "")
    @OperLog(operation = "日志管理",type = LogType.DELETE)
    @RequestMapping(value="/deleteAll",method=RequestMethod.GET)
    @ResponseBody
    public R deleteAll() {
      return iOperationLogService.deleteAll();
    }
}

